<template>
  <el-container>
    <el-aside width="200px">
      <div>
        <SideMenu></SideMenu>
      </div>
    </el-aside>
    <el-container>
      <el-header style="height: 55px;">
        <Strong>Vue-Admin后台管理系统</Strong>
        <div class="header-avatar block">
          <el-avatar class="el-avatar" size="medium" :src="userInfo.avatar"></el-avatar>
          <el-dropdown>
                      <span class="el-dropdown-link">
                        {{userInfo.username}}<i class="el-icon-arrow-down el-icon--right"></i>
                      </span>
            <el-dropdown-menu slot="dropdown">

              <el-dropdown-item :underline="false">
                <router-link :to="{name: 'UserCenter'}">个人中心</router-link>
              </el-dropdown-item>

              <el-dropdown-item :underline="false">
                <router-link :to="{name: 'ResetPass'}">修改密码</router-link>
              </el-dropdown-item>

              <el-dropdown-item @click.native="logout">
                退出
              </el-dropdown-item>

            </el-dropdown-menu>
          </el-dropdown>
          <el-link :underline="false" icon="el-icon-edit" href="http://localhost/login">链接</el-link>
        </div>
      </el-header>

      <el-main>
        <Tabs ref="tabs"></Tabs>
        <div class="el-main-div" style="margin: 0 15px;">
          <router-view></router-view>
        </div>
      </el-main>
    </el-container>
  </el-container>

</template>

<script>
import SideMenu from "@/views/inc/SideMenu";
import Tabs from "@/views/inc/Tabs.vue"
export default {
  name: "Home",
  components: {
    SideMenu, Tabs
  },
  data() {
    return {
      userInfo: {
        id: '-1',
        username: 'admin',
        avatar: 'https://image-1300566513.cos.ap-guangzhou.myqcloud.com/upload/images/5a9f48118166308daba8b6da7e466aab.jpg'
      }
    }
  },
  created() {
    this.getUserInfo()
  },
  methods: {
    getUserInfo() {
      this.$axios.get("/sys/userInfo").then(res => {
        this.userInfo = res.data.data;
      })
    },
    logout() {
      this.$axios.post("/logout").then(res => {
        localStorage.clear()
        sessionStorage.clear()
        this.$store.commit("resetState")
        this.$store.commit("resetUserInfoState")
        this.$router.push("/login")
      })
    }
  }
}
</script>

<style scoped>
.el-container {
  padding: 0;
  margin: 0;
  height: 100%;
}
.header-avatar {
  float: right;
  width: 210px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.el-dropdown-link {
  cursor: pointer;
}
.el-header {
  background-color: #17B3A3;
  color: #333;
  text-align: center;
  line-height: 60px;
}
.el-aside {
  background-color: #545c64;
  color: #333;
  line-height: 200px;
}
.el-main {
  color: #333;
  padding: 0;
}
.el-main-div {
  height: calc(100% - 161px);
}
a {
  text-decoration: none;
}
</style>